package org.fast.develop.logicflow.springboot.configuration.enhance;

import org.fast.develop.logicflow.repository.domain.bytearray.LogicBytearray;
import org.fast.develop.logicflow.repository.domain.bytearray.LogicBytearrayRepository;
import org.fast.develop.logicflow.repository.domain.definition.LogicDefinition;
import org.fast.develop.logicflow.repository.domain.definition.LogicDefinitionRepository;
import org.fast.develop.logicflow.runtime.repository.DefinitionRepositoryEnhance;

/**
 * @author 莫寅
 * @createTime 2022-12-21 02:35
 * @desc：
 */
public class DefaultDefinitionRepositoryEnhance implements DefinitionRepositoryEnhance {

    private LogicDefinitionRepository logicDefinitionRepository;
    private LogicBytearrayRepository logicBytearrayRepository;

    public DefaultDefinitionRepositoryEnhance(LogicDefinitionRepository logicDefinitionRepository, LogicBytearrayRepository logicBytearrayRepository) {
        this.logicDefinitionRepository = logicDefinitionRepository;
        this.logicBytearrayRepository = logicBytearrayRepository;
    }

    @Override
    public byte[] getBytes(String key) {
        LogicDefinition logicDefinition = logicDefinitionRepository.findByMaxVersion(key);
        logicDefinition.getResourceId();
        LogicBytearray logicBytearray = logicBytearrayRepository.get(logicDefinition.getResourceId());
        return logicBytearray.getBytes();
    }
}
